package demo1.NiceDemo;

import af.swing.layout.FreeLayout;
import af.swing.layout.HLayout;
import af.swing.layout.Margin;
import af.swing.layout.VLayout;
import demo1.Layouts.LayoutBox;

import javax.swing.*;

public class LogIn extends JFrame {
    public LogIn(String title) {
        super(title);

        LayoutBox root = new LayoutBox();
        this.setContentPane(root);
        root.padding(15);
        root.layout(new VLayout(10));

        JTextField namefield = new JTextField();
        root.add(creatFormLine("用户名", namefield));

        JTextField passwordfield = new JTextField();
        root.add(creatFormLine("密码", passwordfield));

        JButton logInButton = new JButton("登录");
        LayoutBox box = new LayoutBox().preferredHeight(60).layout(new FreeLayout());
        box.add(logInButton, new Margin(10,55,10,-1));
        root.add(box);
    }
    private LayoutBox creatFormLine(String labelStr, JComponent field) {
        LayoutBox box = new LayoutBox();
        box.layout(new HLayout(5));
        box.preferredHeight(30);

        box.add(new JLabel(labelStr), "50px");
        box.add(field, "1w");
        return box;
    }
}
